// 操作用户信息
// 登录之后 存储个人信息

import {USER_ADD, USER_DELETE, USER_EDIT} from "../actions";

const defaultState = {
  username: '',
  password: '',
  avatar: '',
  uid: ''
};

export function userInfoReducer(state = defaultState, action) {

  let newState = JSON.parse(JSON.stringify(state));

  switch (action.type) {
    case USER_ADD:
      newState = action.userInfo;
      return {...newState};
    case  USER_DELETE:
      newState = defaultState;
      return {...newState};
    case USER_EDIT:
      for (let key in action.userInfo) {
        if (newState.hasOwnProperty(key)) {
          newState[key] = action.userInfo[key];
        }
      }
      return {...newState};
    default :
      return newState;
  }
}
